*********************************************
**** Replication Data - Leaving a Legacy ****
**** Data Cleaning and Preparation File *****
****** Joshua P. Darr & Moriah Harman *******
*********************************************

** Dataset available at: https://doi.org/10.7910/DVN/CYISG1 **



* W6 recode *
use "~/ISCAP Data/iscap_w6.dta", clear

gen state = PPSTATEN

* Watches local news *
gen news_tvlocal = 0
replace news_tvlocal = 1 if ME2A_1==2

gen news_tvnotlocal = abs(news_tvlocal - 1)

* Watches any TV news *
gen news_tv = (ME1_1 - 1)
gen news_tvnone = abs(ME1_1 - 2)

* Reads any newspaper *
gen news_np = (ME1_2 - 1)
gen news_npnone = abs(ME1_2 - 2)

* Watches broadcast news *
gen news_tvbroadcast = 0
replace news_tvbroadcast = 1 if ME2A_2==2 | ME2A_3==2 | ME2A_4==2 | ME2A_6==2 | ME2A_8==2
replace news_tvbroadcast = 1 if ME2B_2==2 | ME2B_5==2 | ME2B_6==2 | ME2B_8==2 | ME2B_9==2

* Watches cable news *
gen news_tvcable = 0
replace news_tvcable = 1 if ME2A_5==2 | ME2A_9==2 | ME2A_13==2
replace news_tvcable = 1 if ME2B_4==2 | ME2B_10==2 | ME2B_11==2 | ME2B_13==2

* Watches entertainment programming *
gen entertainment = 0
replace entertainment = 1 if ME2A_7==2 | ME2A_10==2 | ME2A_12==2
replace entertainment = 1 if ME2B_1==2 | ME2B_3==2 | ME2B_7==2 | ME2B_12==2

* Any national *
gen news_tvnational = 0
replace news_tvnational = 1 if news_tvbroadcast==1 | news_tvcable==1

gen news_tvnotnational = 1 if news_tvnational==0
replace news_tvnotnational = 0 if news_tvnational==1

* TV news specifically *
gen news_tvnews = 0
replace news_tvnews = 1 if news_tvlocal==1
replace news_tvnews = 1 if news_tvnational==1

gen news_notvnews = 0 if news_tvnews==1
replace news_notvnews = 1 if news_tvnews==0


* News online *
gen news_internet = 0
replace news_internet = 1 if ME1_4==2

gen news_nointernet = abs(ME1_4 - 2)

* Find national newspapers *
gen np_name = ME3_newspaper_1
replace np_name = lower(np_name)
replace np_name = subinstr(np_name,"the ","",.)
replace np_name = trim(np_name)

gen np_national=.
replace np_national = 1 if np_name=="wall street journal"
replace np_national = 1 if np_name=="wsj"
replace np_national = 1 if np_name=="washington post"
replace np_national = 1 if np_name=="usa today"
replace np_national = 1 if np_name=="usatoday"
replace np_national = 1 if np_name=="u.s.a. today"
replace np_national = 1 if np_name=="nyt"
replace np_national = 1 if np_name=="nytimes"
replace np_national = 1 if np_name=="ny times"
replace np_national = 1 if np_name=="new york times"
replace np_national = 1 if np_name=="new york time"

replace np_national = 0 if np_name != "" & np_national != 1

gen news_nplocal = 0
replace news_nplocal = 1 if news_np==1
replace news_nplocal = 0 if np_national==1



* Party ID *
gen pid7 =.
replace pid7 = 1 if Q7==3 & Q9==2
replace pid7 = 2 if Q7==3 & Q9==3
replace pid7 = 3 if Q10==3
replace pid7 = 4 if Q10==1
replace pid7 = 5 if Q10==2
replace pid7 = 6 if Q7==2 & Q8==3
replace pid7 = 7 if Q7==2 & Q8==2

gen pid_folded = abs(pid7 - 4)

gen rep_dum_2p = 1 if pid7==5 | pid7==6 | pid7==7
replace rep_dum_2p = 0 if pid7==1 | pid7==2 | pid7==3

gen pid3 = 1 if pid7==1 | pid7==2 | pid7==3
replace pid3 = 2 if pid7==4
replace pid3 = 3 if pid7==5 | pid7==6 | pid7==7

* Election attitudes *
gen election_attention = EP1
replace election_attention =. if election_attention==1
replace election_attention = election_attention - 2
replace election_attention = abs(election_attention - 2)

gen election_money = EP3
replace election_money =. if election_money==1
replace election_money = 0 if EP3==3
replace election_money = 1 if EP3==4
replace election_money = 2 if EP3==2

gen election_faith = EP4
replace election_faith =. if election_faith==1
replace election_faith = election_faith - 2
replace election_faith = abs(election_faith - 4)

gen election_index = ((election_attention/2) + (election_money/2) + (election_faith/4))/3

* System attitudes *
gen system_pref = RE24_1
replace system_pref =. if system_pref==1
replace system_pref = system_pref - 2
replace system_pref = abs(system_pref - 4)

gen system_nochange = RE24_2
replace system_nochange =. if system_nochange==1
replace system_nochange = system_nochange - 2

gen system_best = RE24_3
replace system_best =. if system_best==1
replace system_best = system_best - 2
replace system_best = abs(system_best - 4)

gen system_nocrit = RE24_4
replace system_nocrit =. if system_nocrit==1
replace system_nocrit = system_nocrit - 2

gen system_index = (system_pref/4 + system_nochange/4 + system_best/4 + system_nocrit/4)/4


* Division and polarization *
gen divided = RE10
replace divided =. if divided==1
replace divided = divided - 2

gen disagreement = RE11
replace disagreement =. if disagreement==1
replace disagreement = disagreement - 2

gen polarized = RE12
replace polarized =. if polarized==1
replace polarized = polarized - 1
replace polarized = abs(polarized - 4)

gen extreme = RE13
replace extreme =. if extreme==1
replace extreme = extreme - 1
replace extreme = abs(extreme - 4)

gen polarization_index = (divided/3 + disagreement/3 + polarized/3 + extreme/3)/4


* Media trust *

gen media_confidence = Q3
replace media_confidence =. if media_confidence==1
replace media_confidence = media_confidence - 2
replace media_confidence = abs(media_confidence - 2)

gen media_trust = Q5
replace media_trust =. if media_trust==1
replace media_trust = media_trust - 2
replace media_trust = abs(media_trust - 3)

gen media_fav_cat = Q6
replace media_fav_cat =. if media_fav_cat==1
replace media_fav_cat = media_fav_cat - 2
replace media_fav_cat = abs(media_fav_cat - 3)

gen media_facts = Q7_new
replace media_facts =. if media_facts==1
replace media_facts = 0 if media_facts==2



* Health care opinions *
gen aca_repeal = RE18_1
replace aca_repeal =. if aca_repeal==1 | aca_repeal==9
replace aca_repeal = aca_repeal - 1

* Aid to blacks *
gen aid_blacks = RE23_2 - 1
replace aid_blacks =. if aid_blacks==0

*keep MNO news_local news_notlocal pid7 pid3 rep_dum_2p election_faith system_pref system_nochange system_best system_nocrit system_index aid_blacks

save "iscap_w6_recoded.dta", replace




* W7 recode *
use "~/ISCAP Data/iscap_w7.dta", clear

gen state = PPSTATEN

* Watches local news *
gen news_tvlocal = 0
replace news_tvlocal = 1 if ME2A_1==2

gen news_tvnotlocal = abs(news_tvlocal - 1)

* Watches any TV news *
gen news_tv = (ME1_1 - 1)
gen news_tvnone = abs(ME1_1 - 2)

* Reads any newspaper *
gen news_np = (ME1_2 - 1)
gen news_npnone = abs(ME1_2 - 2)

* Watches broadcast news *
gen news_tvbroadcast = 0
replace news_tvbroadcast = 1 if ME2A_2==2 | ME2A_3==2 | ME2A_4==2 | ME2A_6==2 | ME2A_8==2
replace news_tvbroadcast = 1 if ME2B_2==2 | ME2B_5==2 | ME2B_6==2 | ME2B_8==2 | ME2B_9==2

* Watches cable news *
gen news_tvcable = 0
replace news_tvcable = 1 if ME2A_5==2 | ME2A_9==2 | ME2A_13==2
replace news_tvcable = 1 if ME2B_4==2 | ME2B_10==2 | ME2B_11==2 | ME2B_13==2

* Watches entertainment programming *
gen entertainment = 0
replace entertainment = 1 if ME2A_7==2 | ME2A_10==2 | ME2A_12==2
replace entertainment = 1 if ME2B_1==2 | ME2B_3==2 | ME2B_7==2 | ME2B_12==2

* Any national *
gen news_tvnational = 0
replace news_tvnational = 1 if news_tvbroadcast==1 | news_tvcable==1

gen news_tvnotnational = 1 if news_tvnational==0
replace news_tvnotnational = 0 if news_tvnational==1

* TV news specifically *
gen news_tvnews = 0
replace news_tvnews = 1 if news_tvlocal==1
replace news_tvnews = 1 if news_tvnational==1

gen news_notvnews = 0 if news_tvnews==1
replace news_notvnews = 1 if news_tvnews==0


* News online *
gen news_internet = 0
replace news_internet = 1 if ME1_4==2

gen news_nointernet = abs(ME1_4 - 2)


* Party ID *
gen pid7 =.
replace pid7 = 1 if Q7==3 & Q9==2
replace pid7 = 2 if Q7==3 & Q9==3
replace pid7 = 3 if Q10==3
replace pid7 = 4 if Q10==1
replace pid7 = 5 if Q10==2
replace pid7 = 6 if Q7==2 & Q8==3
replace pid7 = 7 if Q7==2 & Q8==2

gen pid_folded = abs(pid7 - 4)

gen rep_dum_2p = 1 if pid7==5 | pid7==6 | pid7==7
replace rep_dum_2p = 0 if pid7==1 | pid7==2 | pid7==3

gen pid3 = 1 if pid7==1 | pid7==2 | pid7==3
replace pid3 = 2 if pid7==4
replace pid3 = 3 if pid7==5 | pid7==6 | pid7==7


* Election attitudes *
gen election_attention = EP1
replace election_attention =. if election_attention==1
replace election_attention = election_attention - 2
replace election_attention = abs(election_attention - 2)

gen election_money = EP3
replace election_money =. if election_money==1
replace election_money = 0 if EP3==3
replace election_money = 1 if EP3==4
replace election_money = 2 if EP3==2

gen election_faith = EP4
replace election_faith =. if election_faith==1
replace election_faith = election_faith - 2
replace election_faith = abs(election_faith - 4)

gen election_index = ((election_attention/2) + (election_money/2) + (election_faith/4))/3



* System attitudes *
gen system_pref = RE24_1
replace system_pref =. if system_pref==1
replace system_pref = system_pref - 2
replace system_pref = abs(system_pref - 4)

gen system_nochange = RE24_2
replace system_nochange =. if system_nochange==1
replace system_nochange = system_nochange - 2

gen system_best = RE24_3
replace system_best =. if system_best==1
replace system_best = system_best - 2
replace system_best = abs(system_best - 4)

gen system_nocrit = RE24_4
replace system_nocrit =. if system_nocrit==1
replace system_nocrit = system_nocrit - 2

gen system_index = (system_pref/4 + system_nochange/4 + system_best/4 + system_nocrit/4)/4


* Division and polarization *
gen divided = RE10
replace divided =. if divided==1
replace divided = divided - 2

gen disagreement = RE11
replace disagreement =. if disagreement==1
replace disagreement = disagreement - 2

gen polarized = RE12
replace polarized =. if polarized==1
replace polarized = polarized - 1
replace polarized = abs(polarized - 4)

gen extreme = RE13
replace extreme =. if extreme==1
replace extreme = extreme - 1
replace extreme = abs(extreme - 4)

gen polarization_index = (divided/3 + disagreement/3 + polarized/3 + extreme/3)/4


* Media trust *

gen media_confidence = Q3
replace media_confidence =. if media_confidence==1
replace media_confidence = media_confidence - 2
replace media_confidence = abs(media_confidence - 2)

gen media_trust = Q5
replace media_trust =. if media_trust==1
replace media_trust = media_trust - 2
replace media_trust = abs(media_trust - 3)

gen media_fav_cat = Q6
replace media_fav_cat =. if media_fav_cat==1
replace media_fav_cat = media_fav_cat - 2
replace media_fav_cat = abs(media_fav_cat - 3)

gen media_facts = Q7_new
replace media_facts =. if media_facts==1
replace media_facts = 0 if media_facts==2


* Health care opinions *
gen aca_repeal = RE18_1
replace aca_repeal =. if aca_repeal==1 | aca_repeal==9
replace aca_repeal = aca_repeal - 1


* Aid to blacks *
gen aid_blacks = RE23_2 - 1
replace aid_blacks =. if aid_blacks==0

*keep MNO news_local news_notlocal pid7 pid3 rep_dum_2p election_faith system_pref system_nochange system_best system_nocrit system_index aid_blacks


save "iscap_w7_recoded.dta", replace







* W8 recode *
use "~/ISCAP Data/iscap_w8.dta", clear

gen state = PPSTATEN

* Watches local news *
gen news_tvlocal = 0
replace news_tvlocal = 1 if ME2A_1==2

gen news_tvnotlocal = abs(news_tvlocal - 1)

* Watches any TV news *
gen news_tv = (ME1_1 - 1)
gen news_tvnone = abs(ME1_1 - 2)

* Reads any newspaper *
gen news_np = (ME1_2 - 1)
gen news_npnone = abs(ME1_2 - 2)

* Watches broadcast news *
gen news_tvbroadcast = 0
replace news_tvbroadcast = 1 if ME2A_2==2 | ME2A_3==2 | ME2A_4==2 | ME2A_6==2 | ME2A_8==2 | ME2A_4==11
replace news_tvbroadcast = 1 if ME2B_2==2 | ME2B_5==2 | ME2B_6==2 | ME2B_8==2 | ME2B_9==2

* Watches cable news *
gen news_tvcable = 0
replace news_tvcable = 1 if ME2A_5==2 | ME2A_9==2 | ME2A_13==2
replace news_tvcable = 1 if ME2B_4==2 | ME2B_10==2 | ME2B_11==2 | ME2B_13==2

* Watches entertainment programming *
gen entertainment = 0
replace entertainment = 1 if ME2A_7==2 | ME2A_10==2 | ME2A_12==2
replace entertainment = 1 if ME2B_1==2 | ME2B_3==2 | ME2B_7==2 | ME2B_12==2

* Any national *
gen news_tvnational = 0
replace news_tvnational = 1 if news_tvbroadcast==1 | news_tvcable==1

gen news_tvnotnational = 1 if news_tvnational==0
replace news_tvnotnational = 0 if news_tvnational==1

* TV news specifically *
gen news_tvnews = 0
replace news_tvnews = 1 if news_tvlocal==1
replace news_tvnews = 1 if news_tvnational==1

gen news_notvnews = 0 if news_tvnews==1
replace news_notvnews = 1 if news_tvnews==0


* News online *
gen news_internet = 0
replace news_internet = 1 if ME1_4==2

gen news_nointernet = abs(ME1_4 - 2)


* Party ID *
gen pid7 = abs(partyid7 - 10)

gen pid_folded = abs(pid7 - 4)

gen rep_dum_2p = 1 if pid7==5 | pid7==6 | pid7==7
replace rep_dum_2p = 0 if pid7==1 | pid7==2 | pid7==3

gen pid3 = 1 if pid7==1 | pid7==2 | pid7==3
replace pid3 = 2 if pid7==4
replace pid3 = 3 if pid7==5 | pid7==6 | pid7==7

* Election attitudes *
gen election_attention = EP1
replace election_attention =. if election_attention==1
replace election_attention = election_attention - 2
replace election_attention = abs(election_attention - 2)

gen election_money = EP3
replace election_money =. if election_money==1
replace election_money = 0 if EP3==3
replace election_money = 1 if EP3==4
replace election_money = 2 if EP3==2

gen election_faith = EP4
replace election_faith =. if election_faith==1
replace election_faith = election_faith - 2
replace election_faith = abs(election_faith - 4)

gen election_index = ((election_attention/2) + (election_money/2) + (election_faith/4))/3


* System attitudes *
gen system_pref = RE24a
replace system_pref =. if system_pref==1
replace system_pref = system_pref - 2
replace system_pref = abs(system_pref - 4)

gen system_nochange = RE24b
replace system_nochange =. if system_nochange==1
replace system_nochange = system_nochange - 2

gen system_best = RE24c
replace system_best =. if system_best==1
replace system_best = system_best - 2
replace system_best = abs(system_best - 4)

gen system_nocrit = RE24d
replace system_nocrit =. if system_nocrit==1
replace system_nocrit = system_nocrit - 2

gen system_index = (system_pref/4 + system_nochange/4 + system_best/4 + system_nocrit/4)/4

* Division and polarization *
gen divided = RE10
replace divided =. if divided==1
replace divided = divided - 2

gen disagreement = RE11
replace disagreement =. if disagreement==1
replace disagreement = disagreement - 2

gen polarized = RE12
replace polarized =. if polarized==1
replace polarized = polarized - 1
replace polarized = abs(polarized - 4)

gen extreme = RE13
replace extreme =. if extreme==1
replace extreme = extreme - 1
replace extreme = abs(extreme - 4)

gen polarization_index = (divided/3 + disagreement/3 + polarized/3 + extreme/3)/4

* Health care opinions *
gen aca_repeal = RE18a
replace aca_repeal =. if aca_repeal==1 | aca_repeal==9
replace aca_repeal = aca_repeal - 1


*keep MNO news_local news_notlocal pid7 pid3 rep_dum_2p election_faith system_pref system_nochange system_best system_nocrit system_index aid_blacks


save "iscap_w8_recoded.dta", replace




** Create 6-7-8 "TV" dataset **
use "iscap_w6_recoded.dta", clear
foreach x of var * {
	rename `x' `x'__6
	}
rename MNO__6 MNO

save "iscap_w6_recoded_wide.dta", replace

use "iscap_w7_recoded.dta", clear
foreach x of var * {
	rename `x' `x'__7
	}
rename MNO__7 MNO

save "iscap_w7_recoded_wide.dta", replace

use "iscap_w8_recoded.dta", clear
foreach x of var * {
	rename `x' `x'__8
	}
rename MNO__8 MNO

save "iscap_w8_recoded_wide.dta", replace

use "iscap_w6_recoded_wide.dta", clear
merge 1:1 MNO using "iscap_w7_recoded_wide.dta"
drop _merge
merge 1:1 MNO using "iscap_w8_recoded_wide.dta"


gen news_nplocal__7 = news_np__7
replace news_nplocal__7 = 0 if np_national__6==1

gen news_nplocal__8 = news_np__8
replace news_nplocal__8 = 0 if np_national__6==1

gen news_nplocalnone__6 = abs(news_nplocal__6 - 1)
gen news_nplocalnone__7 = abs(news_nplocal__7 - 1)
gen news_nplocalnone__8 = abs(news_nplocal__8 - 1)

gen news_tvnotbroadcast__6 = abs(news_tvbroadcast__6 - 1)
gen news_tvnotbroadcast__7 = abs(news_tvbroadcast__7 - 1)
gen news_tvnotbroadcast__8 = abs(news_tvbroadcast__8 - 1)

gen news_tvnotcable__6 = abs(news_tvcable__6 - 1)
gen news_tvnotcable__7 = abs(news_tvcable__7 - 1)
gen news_tvnotcable__8 = abs(news_tvcable__8 - 1)

save "iscap_678_tv_wide.dta", replace





